<template>
  <div id="addresslist">
    <van-nav-bar
      title="我的收货地址"
      left-text="返回"
      right-text="新增地址"
      left-arrow
      @click-left="onClickLeft"
      @click-right="onAdd"
    />
    <van-address-list
      v-model="chosenAddressId"
      :list="this.$store.state.addresslist"
      @add="onAdd"
      @edit="onEdit"
    />
  </div>
</template>

<script>
import { Toast } from "vant";

export default {
  data() {
    return {
      chosenAddressId: "1",
    };
  },
  mounted(){
    this.$store.commit('addresslist',{ userid: localStorage.getItem("id") })
  },
  methods: {
    onClickLeft() {
      Toast("返回");
      this.$router.go(-1);
    },
    onClickRight() {
      Toast("按钮");
    },
    onAdd() {
      Toast("新增地址");
      this.$router.push("/addressadd");
    },
    onEdit(item) {
      Toast("编辑地址");
      console.log(item);
      console.log(localStorage.getItem("id"));
      this.$router.push({path:'/addressedit',query:{userid:localStorage.getItem("id"),addressid:item.addressid,address:item.address,phone:item.tel,tel:item.tel,name:item.name}})
    },
  },
};
</script>

<style>
</style>